<?php
defined('IN_IA') or exit('Access Denied');
set_time_limit(600);
global $_W, $_GPC;
$setting = $this->baseset($_W['uniacid']);
load()->func('communication');
$itemid = $_POST['itemid'];
if (empty($itemid)) {
	message('请输入商品ID或者大淘客商品ID！', referer(), 'success');
	exit;
}
for ($i = 1; $i <= 1; $i++) {
	$dtkurl = "http://api.dataoke.com/index.php?r=port/index&appkey=" . $setting['dtk_key'] . "&v=2&id=" . $itemid;
	$resp = ihttp_get($dtkurl);
	if (is_error($resp)) {
		$this->json_exit(0, $resp["message"]);
	}
	$dtkData = json_decode($resp['content'], true);
	if ($dtkData['data']['total_num'] >= 1) {
		$result = $dtkData['result'];
		$total = $dtkData['data']['total_num'];
		if ($total == 1) {
			if ($result['GoodsID'] == '') {
				break;
			}
			if ($result['GoodsID'] != '') {
				$cate = pdo_fetch('select * from ' . tablename('bsht_tbk_all_caiji') . " where uniacid = '{$uniacid}' AND itemid = '{$result['GoodsID']}' and uniacid = '{$_W['uniacid']}' limit 1");
				$newurl = "http://uland.taobao.com/coupon/edetail?activityId=" . $result['Quan_id'] . "&pid=" . $setting['tb_pid'] . "&itemId=" . $result['GoodsID'] . "&src=pgy_pgyqf&dx=1";
				$logo = $result['Pic'];
				$text = $result['D_title'] . "【券后价￥" . $result['Price'] . "】";
				if ($result['Commission_queqiao'] > $result['Commission_jihua']) {
					$bili = $result['Commission_queqiao'];
				} else {
					$bili = $result['Commission_jihua'];
				}
				$data = array('atime' => TIMESTAMP, 'uniacid' => $_W['uniacid'], 'displayorder' => '0', 'itemid' => $result['GoodsID'], 'title' => $result['Title'], 'd_title' => $result['D_title'], 'itempic' => $result['Pic'], 'cate_id' => $result['Cid'], 'shoptitle' => $result['Introduce'], 'itemfee' => $result['Org_Price'], 'itemfee2' => $result['Price'], 'itemmsell' => $result['Sales_num'], 'istmall' => $result['IsTmall'], 'itemyhj_fee' => $result['Quan_price'], 'itemyhj_zl' => $result['Quan_surplus'], 'itemyhj_yl' => $result['Quan_surplus'] - $result['Quan_receive'], 'itemyhj_re' => $result['Quan_receive'], 'link_jihua' => $result['Jihua_link'], 'com_jihua' => $result['Commission_jihua'], 'com_queqiao' => $result['Commission_queqiao'], 'status' => 1, 'wenan' => $result['Introduce'], 'itemyhj_tit' => $result['Quan_condition'], 'itemyhj_stime' => TIMESTAMP, 'itemyhj_etime' => $result['Quan_time'], 'itemyhj_url' => $newurl, 'itemurl' => $newurl, 'quan_link' => $result['Quan_link'], 'shouru_bili' => $bili, 'shouru_yongjin' => $result['Org_Price'] * $bili / 100, 'quan_id' => $result['Quan_id'], 'maijia_id' => $result['SellerID'], 'fm' => 'dtk',);
				$data['itemsurl'] = $newurl;
				$data['itemyhj_tkl'] = '';
				$data['itemtkl'] = '';
				if (empty($cate)) {
					pdo_insert('bsht_tbk_all_caiji', $data);
					$cateid = pdo_insertid();
				} else {
					pdo_update($this->modulename . '_all_caiji', $data, array('id' => $cate['id']));
					$cateid = $cate['id'];
				}
			} else {
			}
		}
	} else {
	}
}
message('同步成功！', referer(), 'success');